package com.he;

import com.alibaba.fastjson.JSONObject;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

import java.util.HashMap;
import java.util.Map;

public class TestPing {
    //new Jedis对象即可
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1", 6379);

        Map map = new HashMap();
        map.put("name","hehengjia");
        map.put("age",22);
        map.put("sex","man");
        String s = JSONObject.toJSONString(map);
        Transaction multi = jedis.multi(); //开启事务 try，catch快捷键command+option+t
        try {
            multi.set("address","chenzhou");
            multi.set("id","001");
            multi.set("name","hehengrui");
            multi.exec();
        } catch (Exception e) {
            multi.discard();
            e.printStackTrace();
        }
        finally {
            System.out.println(jedis.get("address"));
            System.out.println(jedis.get("id"));
            jedis.close(); //关闭连接
        }
    }
}
